package com.eop.managedBean;

import java.util.List;

import javax.faces.context.FacesContext;

import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.DataModel;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.annotation.SaveState;
import org.operamasks.faces.component.grid.impl.UIDataGrid;
import org.operamasks.faces.user.util.Browser;

import com.base.commons.SpringBeanHolder;
import com.eop.entity.SpecialInfor;
import com.eop.service.ISpecialInforService;

@ManagedBean(name = "eop_listSpecialInforBean", scope = ManagedBeanScope.REQUEST)
public class ListSpecialInforBean {
	private ISpecialInforService spInfoService = SpringBeanHolder
			.getBean("specialInforService");
	@Inject
	private FacesContext context;
	@Accessible
	@SaveState
	private String eventId = FacesContext.getCurrentInstance()
			.getExternalContext().getRequestParameterMap().get("eventId");
	@Bind(id = "specialInfoGrid", attribute = "binding")
	private UIDataGrid specialInfoGrid_binding;

	@Action(id = "addSpecialInfo")
	public void addSpecialInfo() {
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/addSpecialInfor.faces?eventId=" + eventId;
		String script = "showUrl('" + url + "','新增特殊事件')";
		Browser.execClientScript(script);
	}

	@Action(id = "eidtSpecialInfo")
	public void eidtSpecialInfo() {
		Object[] obj = specialInfoGrid_binding.getSelectedValues();
		if (obj == null || obj.length == 0) {
			Browser.execClientScript("window.alert('请选择一条记录 ！');");
			return;
		}
		SpecialInfor sf = (SpecialInfor) obj[0];
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/addSpecialInfor.faces?id=" + sf.getId();
		String script = "showUrl('" + url + "','编辑特殊事件')";
		Browser.execClientScript(script);
	}

	@Action(id = "deleteSpecialInfo")
	public void deleteSpecialInfo() {
		Object[] obj = specialInfoGrid_binding.getSelectedValues();
		if (obj == null || obj.length == 0) {
			Browser.execClientScript("window.alert('请选择一条记录 ！');");
			return;
		}
		SpecialInfor sf = (SpecialInfor) obj[0];
		sf.setDelFlag(true);
		spInfoService.saveSpecialInfor(sf);
		specialInfoGrid_binding.reload();
	}

	@Action(id = "submit")
	public void showSpecialInfo() {
		String dirId = context.getExternalContext().getRequestParameterMap()
				.get("dirId");
		String url = context.getExternalContext().getRequestContextPath()
				+ "/modules/eop/showSpecialInfor.faces?id=" + dirId;
		String script = "showUrl('" + url + "','查看特殊事件')";
		Browser.execClientScript(script);
	}

	@DataModel(id = "specialInfoGrid")
	private List<SpecialInfor> getSpecialInfoGrid() {
		return spInfoService.getSpecialInforByEvent(eventId);
	}
}
